package 实践.class_09.Demo_01;

abstract class GeometricObject {
    //颜色
    private String color;
    //是否填充
    private boolean filled;
    //构造方法
    public GeometricObject() {
        this.color = "white";
        this.filled = false;
    }
    public GeometricObject(String color, boolean filled) {
        this.color = color;
        this.filled = filled;
    }
    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public boolean getFilled() {
        return filled;
    }

    public void setFilled(boolean filled) {
        this.filled = filled;
    }

    @Override
    public String toString() {
        return "GeometricObject{color = " + color + ", filled = " + filled + "}";
    }

    public abstract int compareTo(Circle circle);
}

class Circle extends GeometricObject implements Comparable<Circle> {
    //圆的半径
    private double radius;
    //构造方法
    public Circle(){}
    public Circle(String color, boolean filled, double radius) {
        super(color, filled);
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

//    public boolean equals(Object obj) {
//        // 首先检查是否是同一个对象引用
//        if (this == obj) {
//            return true;
//        }
//        // 检查 obj 是否为 null 或者不是 Circle 类型的实例
//        if (obj == null || getClass() != obj.getClass()) {
//            return false;
//        }
//        // 将 obj 强制转换为 Circle 类型
//        Circle other = (Circle) obj;
//        if (this.radius == ((Circle) obj).getRadius() && this.getColor()==(Circle) obj).getColor() && this.getFilled() == (Circle) obj).getFilled()) {
//            return true;
//        }
//        return false;
//    }
    public boolean equals(Object obj) {
        // 首先检查是否是同一个对象引用
        if (this == obj) {
            return true;
        }
        // 检查 obj 是否为 null 或者不是 Circle 类型的实例
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        // 将 obj 强制转换为 Circle 类型
        Circle other = (Circle) obj;
        return this.radius == other.getRadius() &&
                this.getColor().equals(other.getColor()) &&
                this.getFilled() == other.getFilled();
    }

    @Override
    public int compareTo(Circle circle) {
        if (this.radius > circle.getRadius()) {
            return 1;
        } else if (this.radius < circle.getRadius()) {
            return -1;
        } else {
            return 0;
        }
    }
}
